home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / pine3.92 / pine / osdep / pw_stuff < prev    next >
Text File  |  1994-06-17  |  2KB  |  84 lines

  1. /*----------------------------------------------------------------------
  2.       Pull the name out of the gcos field if we have that sort of /etc/passwd
  3.  
  4.    Args: gcos_field --  The long name or GCOS field to be parsed
  5.          logname    --  Replaces occurances of & with logname string
  6.  
  7.  Result: returns pointer to buffer with name
  8.   ----*/
  9. static char *
  10. gcos_name(gcos_field, logname)
  11.     char *logname, *gcos_field;
  12. {
  13.     static char fullname[MAX_FULLNAME+1];
  14.     register char *fncp, *gcoscp, *lncp, *end;
  15.  
  16.     /* full name is all chars up to first ',' (or whole gcos, if no ',') */
  17.     /* replace any & with logname in upper case */
  18.  
  19.     for(fncp = fullname, gcoscp= gcos_field, end = fullname + MAX_FULLNAME - 1;
  20.         (*gcoscp != ',' && *gcoscp != '\0' && fncp != end);
  21.     gcoscp++) {
  22.  
  23.     if(*gcoscp == '&') {
  24.         for(lncp = logname; *lncp; fncp++, lncp++)
  25.         *fncp = toupper(*lncp);
  26.     } else {
  27.         *fncp++ = *gcoscp;
  28.     }
  29.     }
  30.     
  31.     *fncp = '\0';
  32.     return(fullname);
  33. }
  34.  
  35.  
  36. /*----------------------------------------------------------------------
  37.       Fill in homedir, login, and fullname for the logged in user.
  38.       These are all pointers to static storage so need to be copied
  39.       in the caller.
  40.  
  41.  Args: ui    -- struct pointer to pass back answers
  42.  
  43.  Result: fills in the fields
  44.   ----*/
  45. void
  46. get_user_info(ui)
  47.     struct user_info *ui;
  48. {
  49.     struct passwd *unix_pwd;
  50.  
  51.     unix_pwd = getpwuid(getuid());
  52.     if(unix_pwd == NULL) {
  53.       ui->homedir = cpystr("");
  54.       ui->login = cpystr("");
  55.       ui->fullname = cpystr("");
  56.     }else {
  57.       ui->homedir = cpystr(unix_pwd->pw_dir);
  58.       ui->login = cpystr(unix_pwd->pw_name);
  59.       ui->fullname = cpystr(gcos_name(unix_pwd->pw_gecos, unix_pwd->pw_name));
  60.     }
  61. }
  62.  
  63.  
  64. /*----------------------------------------------------------------------
  65.       Look up a userid on the local system and return rfc822 address
  66.  
  67.  Args: name  -- possible login name on local system
  68.  
  69.  Result: returns NULL or pointer to alloc'd string rfc822 address.
  70.   ----*/
  71. char *
  72. local_name_lookup(name)
  73.     char *name;
  74. {
  75.     struct passwd *pw = getpwnam(name);
  76.  
  77.     if(pw == NULL)
  78.       return((char *)NULL);
  79.  
  80.     return(cpystr(gcos_name(pw->pw_gecos, name)));
  81. }
  82.  
  83.  
  84.